package com.example.cinema;

import java.util.Date;

public class Session {
    private String id;
    private Movie movie;
    private Hall hall;
    private Date time;
    private double price;
    private boolean[][] seats; // 座位状态：true=已售

    public Session(String id, Movie movie, Hall hall, Date time, double price) {
        this.id = id;
        this.movie = movie;
        this.hall = hall;
        this.time = time;
        this.price = price;
        // 初始化座位（默认全空）
        this.seats = new boolean[hall.getRowCount()][hall.getSeatPerRow()];
    }

    // 检查座位是否可用
    public boolean isSeatAvailable(int row, int seat) {
        return !seats[row-1][seat-1]; // 行/座从1开始
    }

    // 锁定座位（售票）
    public boolean lockSeat(int row, int seat) {
        if (isSeatAvailable(row, seat)) {
            seats[row-1][seat-1] = true;
            return true;
        }
        return false;
    }

    // 解锁座位（退票）
    public void unlockSeat(int row, int seat) {
        seats[row-1][seat-1] = false;
    }

    // getter
    public String getId() { return id; }
    public Movie getMovie() { return movie; }
    public Hall getHall() { return hall; }
    public Date getTime() { return time; }
    public double getPrice() { return price; }
    public boolean[][] getSeats() { return seats; }
}

